package car.aistar.service.impl;

import car.aistar.dao.UserDetailDao;
import car.aistar.entity.UserDetail;
import car.aistar.service.UserDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (UserDetail)表服务实现类
 *
 * @author makejava
 * @since 2020-09-30 20:57:58
 */
@Service("userDetailService")
public class UserDetailServiceImpl implements UserDetailService {



    @Resource
    private UserDetailDao userDetailDao;
    /**
     *@Author 肖相荣
     *@Description //TODO 管理员页面用户表的全局搜索
     *@Date 15:16 2020/10/7
     *@Param [search]
     *@return java.util.List<car.aistar.entity.UserDetail>
     **/
    @Override
    public List<UserDetail> findAllUser (String search){
        return userDetailDao.findAllUser(search);
    }

    /**
     *@Author 肖相荣
     *@Description //TODO 管理员页面用户表的全局搜索分页
     *@Date 15:16 2020/10/7
     *@Param [search, pageNow, pageSize]
     *@return com.github.pagehelper.PageInfo<car.aistar.entity.UserDetail>
     **/
    @Override
    public PageInfo<UserDetail> findByPageUser (String search, Integer pageNow, Integer pageSize){
        PageHelper.startPage(pageNow,pageSize);
        List<UserDetail> userDetailList = userDetailDao.findAllUser(search);
        PageInfo<UserDetail> petPageInfo = new PageInfo<>(userDetailList);
        return petPageInfo;
    }



    @Override
    public List<UserDetail> findAll (){
        return userDetailDao.findAll();
    }

    @Override
    public List<UserDetail> queryAll(UserDetail userDetail) {
        return this.userDetailDao.queryAll(userDetail);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public UserDetail queryById(Long id) {
        return this.userDetailDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<UserDetail> queryAllByLimit(int offset, int limit) {
        return this.userDetailDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param userDetail 实例对象
     * @return 实例对象
     */
    @Override
    public UserDetail insert(UserDetail userDetail) {
        this.userDetailDao.insert(userDetail);
        return userDetail;
    }

    /**
     * 修改数据
     *
     * @param userDetail 实例对象
     * @return 实例对象
     */
    @Override
    public UserDetail update(UserDetail userDetail) {
        this.userDetailDao.update(userDetail);
        return this.queryById(userDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.userDetailDao.deleteById(id) > 0;
    }
}